<template>
	<view>
		<!-- 搜索框组件 -->
		<view class="search-box">
			<my-search @myclick="goSearch"></my-search>
		</view>
		
		<!-- 轮播图 -->
		<swiper circular indicator-dots="true" autoplay="true" interval="2000" duration="500">
			<swiper-item v-for="(item,index) in swiperList" :key="item.goods_id">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id='+ item.goods_id">
					<img :src="item.image_src" alt="" />
				</navigator>
			</swiper-item>
		</swiper>
		<!-- 分类导航 -->
		<view class="nav-list">
			<view class="nav-item" v-for="(item,index) in NavList" :key="index" @click=navClickHandler(item)>
				<img :src="item.image_src" alt="" class="nav-img" />
			</view>
		</view>
		<!-- 楼层数据 -->
		<view class="floor-list">
			<view class="floor-item" v-for="(item,index) in FloorList" :key=index>
				<!-- 一级标题 -->
				<img :src="item.floor_title.image_src" alt="" class="floor-title" />
				<!-- 图片展示 -->
				<view class="floor-img-box">
					<!-- 左边大图 -->
					<navigator class="left-img-box" :url="item.product_list[0].url">
						<view class="">
							<img :src="item.product_list[0].image_src" alt=""
								:style="{width:item.product_list[0].image_width + 'rpx'}" mode="widthFix" />
						</view>
					</navigator>
					<!-- 右边四小图 -->
					<view class="right-img-box">
						<navigator class="right-image-item" v-for="(item2,index2) in item.product_list" :key=index2
							v-if="index2!==0" :url="item2.url">
							<img :src="item2.image_src" alt="" :style="{width:item2.image_width + 'rpx'}"
								mode="widthFix" />
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	export default {
		mixins: [badgeMix],
		data() {
			return {
				// 轮播图数据
				swiperList: [],
				// 分类导航数据,
				NavList: [],
				// 楼层数据
				FloorList: [],

			}
		},
		methods: {
			// 获取轮播图数据
			async getSwiperList() {
				let result = await uni.$http.get('/api/public/v1/home/swiperdata')
				if (result.statusCode == 200) {
					this.swiperList = result.data.message
				}
			},
			// 获取分类导航数据
			async getNavList() {
				let result = await uni.$http.get('/api/public/v1/home/catitems')
				if (result.statusCode == 200) {
					this.NavList = result.data.message
				}
			},
			// 分类导航的点击跳转
			navClickHandler(item) {
				if (item.name == "分类") {
					uni.switchTab({
						url: '/pages/cate/cate'
					})
				}
			},
			// 获取楼层数据
			async getFloorList() {
				let result = await uni.$http.get('/api/public/v1/home/floordata')
				if (result.statusCode == 200) {
					// 处理url跳转路径
					result.data.message.forEach(floor=>{
						floor.product_list.forEach(prod=>{
							prod.url = "/subpkg/goods_list/goods_list?" + prod.navigator_url.split('?')[1]
						})
					})
					
					this.FloorList = result.data.message
					console.log(this.FloorList)
				}
			},
			// 触发搜索框的自定义事件
			goSearch(){
				uni.navigateTo({
					url:'/subpkg/search/search'
				})
			}
			
		},
		onLoad() {
			this.getSwiperList()
			this.getNavList()
			this.getFloorList()
		}
	}
</script>

<style lang="scss">
	// 轮播图效果
	swiper {
		height: 330rpx;

		.swiper-item,
		img {
			width: 100%;
			height: 100%;
		}
	}

	// 分类导航效果
	.nav-list {
		display: flex;
		justify-content: space-around;
		margin: 15px 0;

		.nav-img {
			width: 120rpx;
			height: 140rpx;
		}
	}

	// 楼层数据
	.floor-title {
		width: 100%;
		height: 60rpx;
	}

	.floor-img-box {
		display: flex;
		padding-left: 10rpx;
	}

	.right-img-box {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
	}
	
	//搜索框粘性定位
	 .search-box{
		 position:sticky;
		 top:0;
		 z-index:999;
	 }
</style>